Skip to content

Parallel testing for faster local testing [Deprecated]#349

Closed
shaypal5 wants to merge 22 commits intomasterfrom
testing-improvements
Closed

Parallel testing for faster local testing [Deprecated]#349
shaypal5 wants to merge 22 commits intomasterfrom
testing-improvements

Conversation

@shaypal5
Copy link
Member

@shaypal5 shaypal5 commented Feb 28, 2026

This pull request introduces parallel test execution support to the testing infrastructure, improving test speed and reliability. It adds new pytest fixtures and configuration to enable safe parallelization, including worker-specific isolation for SQL and cache-based tests. The test runner script (test-local.sh) is enhanced with options for parallel execution, and the test dependencies are updated accordingly.

Key changes include:

Parallel Test Execution Support:

  • Added pytest-xdist and related plugins to tests/requirements.txt to enable parallel test execution and automatic retries for flaky tests.
  • Implemented new command-line options (-p/--parallel, -w/--workers) in scripts/test-local.sh to run tests in parallel and specify the number of workers. The script now installs pytest-xdist if needed and handles serial vs. parallel test execution, including special handling for pickle and memory tests. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Test Isolation and Fixtures:

  • Added tests/conftest.py with fixtures for:
    • Worker-specific PostgreSQL schema isolation for SQL tests, allowing safe parallelization without table conflicts.
    • Isolated cache directories for pickle and maxage tests, preventing cross-worker interference.
    • Cleanup of worker-specific schemas after tests complete.
    • Custom pytest options for parallel testing.

Configuration Updates:

  • Updated pyproject.toml:
    • Added tool.black configuration for consistent formatting.
    • Extended ruff ignores for additional security warnings.
    • Added new pytest markers for flaky and serial-local tests.
    • Documented and enabled parallel coverage collection.
    • Enhanced pytest options and documentation for parallel execution. [1] [2] [3] [4] [5]

These changes collectively make the test suite faster, more robust, and ready for parallel execution, especially important for large or slow-running test suites.

@shaypal5
Copy link
Member Author

@copilot fix precommit-ci errors:

pre-commit.ci
home
docs
pre-commit.com
login
python-cachier / cachier · #349 
queued at: 2026-02-28 21:06:37.638526

total time to completion: 41.8s





fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
check json...........................................(no files to check)Skipped
check yaml...............................................................Passed
check toml...............................................................Passed
check docstring is first.................................................Passed
check that executables have shebangs.....................................Passed
check for case conflicts.................................................Passed
check for added large files..............................................Passed
detect private key.......................................................Passed
typos....................................................................Passed
docformatter.............................................................Passed
mdformat.................................................................Passed
prettier.................................................................Passed
Black by Ruff............................................................Passed
Ruff check...............................................................Failed
- hook id: ruff-check
- exit code: 1

warning: `incorrect-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `incorrect-blank-line-before-class`.
warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`.
SIM108 Use ternary operator `cache_dir = tmp_path / "cachier_cache" if worker_id == "master" else tmp_path / f"cachier_cache_{worker_id}"` instead of `if`-`else`-block
   --> tests/conftest.py:153:9
    |
151 |       if "pickle" in request.node.keywords:
152 |           # Create a unique cache directory for this test
153 | /         if worker_id == "master":
154 | |             # Not running in parallel mode
155 | |             cache_dir = tmp_path / "cachier_cache"
156 | |         else:
157 | |             # Running with pytest-xdist - use worker-specific directory
158 | |             cache_dir = tmp_path / f"cachier_cache_{worker_id}"
    | |_______________________________________________________________^
159 |
160 |           cache_dir.mkdir(exist_ok=True, parents=True)
    |
help: Replace `if`-`else`-block with `cache_dir = tmp_path / "cachier_cache" if worker_id == "master" else tmp_path / f"cachier_cache_{worker_id}"`

Found 1 error.

mypy.....................................................................Passed
pyproject-fmt............................................................Passed
Validate pyproject.toml..................................................Passed
©[ pre-commit.ci](https://results.pre-commit.ci/)  ·  contact  ·  security  ·  privacy policy  ·  cookie notice  ·  issues

Copy link
Contributor

Copilot AI commented Feb 28, 2026

@shaypal5 I've opened a new pull request, #350, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to speed up local development workflows by enabling parallel pytest execution (via pytest-xdist), adding retry support for flaky tests, and documenting the test suite / parallel execution behavior.

Changes:

  • Add pytest-xdist + pytest-rerunfailures to the base test requirements.
  • Introduce new pytest fixtures/configuration intended to improve isolation when running tests in parallel (SQL schema isolation, per-worker cache dirs).
  • Extend scripts/test-local.sh and add test-suite documentation under tests/README.md.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
tests/requirements.txt Adds dependencies for parallel runs / flaky retries (but currently drops an async dependency needed by the suite).
tests/conftest.py Adds fixtures/options to support parallel-safe execution across backends (SQL schema + cache-dir isolation).
tests/README.md Adds comprehensive test-suite and parallel-execution documentation.
scripts/test-local.sh Adds -p/-w support and attempts to split out serial local tests while running the rest in parallel.
pyproject.toml Updates pytest/coverage configuration and adds a Black config section.
Comments suppressed due to low confidence (1)

tests/conftest.py:240

  • The custom --parallel / --parallel-workers options are added here but aren’t used anywhere (no hook that converts them into xdist’s -n behavior). As a result, running pytest --parallel will not actually run tests in parallel. Either implement the wiring (e.g., translate these options into -n) or drop these custom options to avoid a misleading CLI.
        default="auto",
        help="Number of parallel workers (default: auto)",
    )

Copy link
Contributor

Copilot AI commented Feb 28, 2026

@shaypal5 I've opened a new pull request, #351, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Feb 28, 2026

@shaypal5 I've opened a new pull request, #352, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Feb 28, 2026

@shaypal5 I've opened a new pull request, #353, to work on those changes. Once the pull request is ready, I'll request review from you.

shaypal5 and others added 18 commits March 2, 2026 00:05
* Initial plan

* Fix SIM108: use ternary operator for cache_dir assignment in conftest.py

Co-authored-by: shaypal5 <917954+shaypal5@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: shaypal5 <917954+shaypal5@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…flow (#351)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: shaypal5 <917954+shaypal5@users.noreply.github.com>
* Fix SQL test module path in conftest.py fixture

Co-authored-by: shaypal5 <917954+shaypal5@users.noreply.github.com>

* Initial plan

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: shaypal5 <917954+shaypal5@users.noreply.github.com>
…354)

* Initial plan

* Extend isolated_cache_directory fixture to cover maxage-marked tests

Co-authored-by: shaypal5 <917954+shaypal5@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: shaypal5 <917954+shaypal5@users.noreply.github.com>
* Initial plan

* Add pytest-asyncio back to tests/requirements.txt

Co-authored-by: shaypal5 <917954+shaypal5@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: shaypal5 <917954+shaypal5@users.noreply.github.com>
)

* Initial plan

* Fix regression: only apply cache isolation in parallel (xdist) mode

Co-authored-by: shaypal5 <917954+shaypal5@users.noreply.github.com>

* Apply ruff format to conftest.py to fix pre-commit.ci formatting error

Co-authored-by: shaypal5 <917954+shaypal5@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: shaypal5 <917954+shaypal5@users.noreply.github.com>
@shaypal5
Copy link
Member Author

shaypal5 commented Mar 4, 2026

@Borda Hey! Please take a look and review. :)

Copy link
Contributor

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though the testing time seems almost the same, and for CI, the most time-consuming steps is start DB in Docker for 5 minutes

UPDATE: why don't you run parallel tests also in CI?

@Borda
Copy link
Contributor

Borda commented Mar 6, 2026

@copilot why don't you run parallel tests also in CI?

Copy link
Contributor

Copilot AI commented Mar 6, 2026

@Borda I've opened a new pull request, #359, to work on those changes. Once the pull request is ready, I'll request review from you.

@Borda
Copy link
Contributor

Borda commented Mar 6, 2026

@shaypal5 seems pre-commit bot is disabled so not linting fixes are pusched to the PR

* Initial plan

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add parallel test execution (-n auto) to CI workflow

Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
@shaypal5
Copy link
Member Author

shaypal5 commented Mar 6, 2026

Hey @Borda , please let's finish parallel test execution for local running first, then open a separate PR for its use in the CI.

Please roll back this branch to commit 4a4f2ca, which passed and for which I asked you for a review, and then review it so we can merge it.

Then, you can cherry pick your newer commits to a new branch out of this branch or main, and open a PR when this actually works in the CI. :)

@shaypal5
Copy link
Member Author

shaypal5 commented Mar 6, 2026

Nevermind. Please review PR #360 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants